/*

You can now create a spinner using any of the variants below:

$("#el").spin(); // Produces default Spinner using the text color of #el.
$("#el").spin({ ... }); // Produces a Spinner using your custom settings.

$("#el").spin(false); // Kills the spinner.

*/
$(function () {
    $.fn.spin = function (pParamOptions) {
        var pParamDefaults = {
            lines: 13,
            length: 5,
            width: 2,
            radius: 6,
            corners: 0.4,
            shadow: false,
            hwaccel: true,
            zIndex: 2e9
        },
        pParamNewOptions = $.extend({}, pParamDefaults, pParamOptions);

        if (Spinner) {
            return this.each(function () {
                var $this = $(this),
                data = $this.data();

                if (data.spinner) {
                    data.spinner.stop();
                    delete data.spinner;
                }
                if (pParamOptions !== false) {
                    data.spinner = new Spinner(pParamNewOptions).spin(this);
                    //Fix overflow-x
                    $('.spinner').css({ width: 50 });
                }
            });
        } else {
            throw "Spinner class not available.";
        }
    };
});